﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Jaiden.Runtime.InteropServices;

namespace Jaiden.Net.Http
{
    static class UnsafeNativeMethods
    {
        static UnsafeNativeMethods()
        {
            var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Environment.Is64BitProcess ? "x64" : "x86", DllName);
            LoadLibraryA(fileName);
        }
        private const string DllName = "Jaiden.Net.Http.Interop.dll";
        private const CallingConvention CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl;
        [DllImport("kernel32")]
        private static extern IntPtr LoadLibraryA([MarshalAs(UnmanagedType.LPStr)] string fileName);

        [DllImport(DllName, EntryPoint = "Free", CallingConvention = CallingConvention)]

        internal static extern void Free(IntPtr intPtr);

        [DllImport(DllName, EntryPoint = "Send", CallingConvention = CallingConvention)]
        internal static extern void Send(
            [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]
            String request,
            SendCallback callback
            );
    }
}
